<!DOCTYPE html>
<html>
<head>
	<title>用户中心</title>
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta charset="utf-8">
	<link rel="stylesheet" href="../static/css/main.css">
	<script src="../static/js/vue.js"></script>
	<script src="../static/js/axios.js"></script>
	<script src="../static/js/uuid.js"></script>
	<script src="../static/js/main.js"></script>
</head>
<body>
	<div class="app frame avatar update_password" id="app">
    <div class="box">
      <p class="title">修改交易密码</p>
      <img class="close" @click="back" src="../static/images/close_btn1.png" alt="">
      <div class="content">
				<input class="password" type="text" v-model="old_password" placeholder="原密码....">
				<input class="password password2" type="text" v-model="password" placeholder="新密码....">
				<input class="password password2" type="text" v-model="password2" placeholder="确认新密码....">
      </div>
      <img @click="update_password_commit" class="btn" src="../static/images/yes.png" alt="">
    </div>
	</div>
	<script>
	apiready = function(){
    var game = new Game("../static/mp3/bg1.mp3");
    // 在 #app 标签下渲染一个按钮组件
    Vue.prototype.game = game;
    new Vue({
			el:"#app",
			data(){
				return {
          old_password: "", //原密码
          password:"",
					password2:"",
					prev:{name:"",url:"",params:{}},
					current:{name:"password",url:"password.html",params:{}},
				}
			},
			methods:{
        back(){
          this.game.closeFrame();
        },
        update_password_commit(){
          // 提交用户密码
          if(this.old_password.length<1 || this.password.length<1){
            this.game.tips("原密码或新密码不能为空！");
            return false;
          }

          if(this.password.length<6 || this.password.length > 16){
            this.game.tips("新密码长度在6~16个字符之间！");
            return false;
          }

          if(this.password != this.password2){
            this.game.tips("新密码或确认新密码不一致！");
            return false;
          }
          let access_token = this.game.getdata("access_token") || this.game.getfs("access_token");
          let self = this;
          this.game.post(this,{
            "method": "Users.transation_password",
            "params": {
              "old_password": this.old_password,
              "new_password": this.password,
              "re_password": this.password2
            },
            "header":{"Authorization": "jwt " + access_token},
            success(response){
              var data = response.data;
              if(data.result && data.result.errno == 1000){
                // 关闭当前页面
                self.game.tips("修改交易密码成功！");
                setTimeout(()=>{
                  self.game.closeFrame();
                },2000);
              }
            }
          });

        }
			}
		});
	}
	</script>
</body>
</html>
